package com.sc.portal.service.impl;

import com.sc.common.pojo.CommonResult;
import com.sc.common.pojo.SearchResult;
import com.sc.common.utils.HttpClientUtil;
import com.sc.portal.service.SearchService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @auther sc
 * @Date 2017/10/26
 */
@Service
public class SearchServiceImpl implements SearchService {


    @Value("${SEARCH_BASE_URL}")
    private String SEARCH_BASE_URL;

    @Override
    public SearchResult search(String keyword, int page, int rows) {
        Map<String,String> map = new HashMap<String, String>();
        map.put("keyword",keyword);
        map.put("page",page+"");
        map.put("rows",rows+"");
        String json = HttpClientUtil.doGet(SEARCH_BASE_URL,map);
        CommonResult commonResult = CommonResult.formatToPojo(json,SearchResult.class);
        SearchResult data = (SearchResult) commonResult.getData();
        return data ;
    }
}
